package com.youshuit.designmodedemo.service.impl.adapter;

import com.youshuit.designmodedemo.service.AdvancedMediaPlayer;
import com.youshuit.designmodedemo.service.MediaPlayer;

/**
 * @author zhongzm
 * @date 2025-11-04 11:42
 */
public class MediaAdapter implements MediaPlayer {

    AdvancedMediaPlayer advancedMusicPlayer;

    public MediaAdapter(String audioType) {
        if (audioType.equalsIgnoreCase("vlc")) {
            this.advancedMusicPlayer = new VlcPlayerService();
        } else if (audioType.equalsIgnoreCase("mp4")) {
            this.advancedMusicPlayer = new Mp4PlayerService();
        } else {
            System.out.println("不支持播放该文件类型");
        }
    }

    @Override
    public void play(String audioType, String fileName) {
        if (audioType.equalsIgnoreCase("vlc")) {
            advancedMusicPlayer.playVlc(fileName);
        } else if (audioType.equalsIgnoreCase("mp4")) {
            advancedMusicPlayer.playMp4(fileName);
        } else {
            System.out.println("不支持播放该文件类型");
        }
    }
}
